package Day02;

import java.util.Scanner;

/**
 * 二维前缀和
 * 初始化： s[i][j] = s[i-1][j] + s[i][j-1] - s[i-1][j-1] + arr[i][j]
 * 子矩阵计算： x1,y1,x2,y2
 *          s[x2][y2] - s[x2][y1 - 1] - s[x1 - 1][y2] + s[x1 - 1][y1 - 1]
 */
public class TwoPrefixSum {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int[][] arr = new int[Common.N][Common.N];
        int[][] s = new int[Common.N][Common.N];
        int n = scanner.nextInt();
        int m = scanner.nextInt();
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= n; j++) {
                arr[i][j] = scanner.nextInt();
            }
        }
        // 前缀和的初始化
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= n; j++) {
                s[i][j] = s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1] + arr[i][j];
            }
        }
        int x1 = scanner.nextInt();
        int y1 = scanner.nextInt();
        int x2 = scanner.nextInt();
        int y2 = scanner.nextInt();
        while (m != 0) {
            // 子矩阵计算
            System.out.printf("%d\n", s[x2][y2] - s[x2][y1 - 1] - s[x1 - 1][y2] + s[x1 - 1][y1 - 1]);
            m--;
        }
    }
}
